import random

from fastapi import FastAPI

app = FastAPI(
    title="Workers Salaries"
)

workers_base = [
    {"id": 1, "user_name": "Sergey", "salary": 30000, "next_accrual_date": "12.06.24", "login": "sergey_login",
     "password": "sergey_password"},
    {"id": 2, "user_name": "Maksim", "salary": 45000, "next_accrual_date": "15.06.24", "login": "maksim_login",
     "password": "maksim_password"},
    {"id": 3, "user_name": "Denis", "salary": 25000, "next_accrual_date": "20.06.24", "login": "denis_login",
     "password": "denis_password"}
]


def generate_token():
    length_token = 40
    chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&*+-=?@^_"
    rand_password = ''.join(random.choice(chars) for i in range(length_token))
    return rand_password


individual_token = generate_token()
information = {}


@app.get("/workers")
async def workers_info(user_login: str, user_password: str):
    for worker in workers_base:
        if worker.get("login") == user_login and worker.get("password") == user_password:
            return [individual_token]
        return ["Invalid data!"]


@app.get("/salary_workers")
async def input_token(token: str):
    for worker in workers_base:
        if token == individual_token:
            return [worker["salary"], worker["next_accrual_date"]]
    return ["Sorry, you are trying to hack your account"]
